using System;
using System.Data;
using System.Collections.Generic;
using System.Data.SqlClient;
using Core;

namespace DataAccess
{
    public class tbMenu : Popular
    {

        public int MenuID { get; set; }
        public int ParentID { get; set; }
        public string MenuName { get; set; }
        public string Description { get; set; }
        public string HTML { get; set; }
        public int OrderID { get; set; }
        public string Link { get; set; }
        public int OrgID { get; set; }
        Common<tbMenu> cm = new Common<tbMenu>();
        public bool Insert(Popular b)
        {
            return cm.Insert(b as tbMenu, "sp_tbMenu_Insert");
        }
        public bool Update(Popular b)
        {
            return cm.UpDate(b as tbMenu, "sp_tbMenu_Update");
        }
        public bool Delete(object b)
        {
            return cm.Delete(b, "sp_tbMenu_Delete");
        }
        public IDataReader Select_ID(object b)
        {
            return cm.Select_ID(b, "sp_tbMenu_SelectByID");
        }
        public IDataReader Select_Name(object b)
        {
            return cm.Select_Name(b, "sp_tbMenu_SelectByName");
        }
        public IDataReader SelectAll()
        {
            return cm.Select_All("sp_tbMenu_SelectAll");
        }
        public List<tbMenu> SelectAllToList()
        {
            return cm.SelectAll<tbMenu>("sp_tbMenu_SelectAll");
        }
        public List<tbMenu> GetParentMenu()
        {
            try
            {
                return CBO.FillCollection<tbMenu>(DataProvider.Instance.ExecuteReader("GetMenuByParentID", 0));
            }
            catch (Exception)
            {
                return null;
            }
        }

        public List<tbMenu> GetMenuChild(int MenuParentID)
        {
            try
            {
                return CBO.FillCollection<tbMenu>(DataProvider.Instance.ExecuteReader("GetMenuByParentID", MenuParentID));
            }
            catch (Exception)
            {
                return null;
            }
        }

        public string GetContentMenu(int menuID)
        {
            return DataProvider.Instance.ExecuteScalar("GetContentMenu", menuID).ToString();
        }

        public tbMenu Single(int menuID)
        {
            try
            {
                return CBO.FillObject<tbMenu>(DataProvider.Instance.ExecuteReader("GetSingle", menuID));
            }
            catch
            {
                return null;
            }
        }
        public tbMenu SinglePath(int menuID)
        {
            try
            {
                return CBO.FillObject<tbMenu>(DataProvider.Instance.ExecuteReader("GetSinglePath", menuID));
            }
            catch
            {
                return null;
            }
        }

        public tbMenu GetByLink(string link)
        {
            try
            {
                return CBO.FillObject<tbMenu>(DataProvider.Instance.ExecuteReader("sp_tbMenu_GetByLink", link));
            }
            catch
            {
                return null;
            }
        }

    }
}